package scuts.core.extensions;

#if macro
import haxe.macro.Expr;
#end
class Arrays 
{

  #if stax
  @:macro public static function asList (arr:ExprRequire<Array<Dynamic>>, baseType:Expr, ?order:Expr, ?equal:Expr, ?hash:Expr, ?show:Expr):Expr 
  {
    return scuts.core.macros.MakeStaxList.asStaxList(arr, baseType, order, equal, hash, show);
  }
  #end
  @:macro public static function asTuple (arr:ExprRequire<Array<Dynamic>>) {
     return scuts.core.macros.MakeTuple.asTuple(arr);
  }
  
  public static function shuffle <T>(arr:Array<T>):Array<T> 
  {
    var res = [];
    var cp = arr.copy();
    while (cp.length > 0) {
      var randIndex = Math.floor(Math.random()*cp.length);
      res.push(cp.splice(randIndex,1)[0]);
    }
    return res;
  }
  
 
}
